package main.service;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import main.dao.ThreadsDAO;
import main.dao.UserDAO;
import main.entity.ThreadsVO;
import main.entity.UserVO;
import main.utils.TimeUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


//@Transactional
@Service("threadsService")
public class ThreadsService extends BaseService<ThreadsVO> {

	@Autowired
	private ThreadsDAO threadsDAO;
	@Resource
	private UserDAO userDAO;
	
	@Override
	public ThreadsVO getByID(Class<ThreadsVO> entityClass, Serializable UID){
		ThreadsVO threadsVO = getBaseDAO().getByID(entityClass, UID);		
		UserVO userVO = userDAO.getByID(UserVO.class, threadsVO.getuID());
		threadsVO.setUnm(userVO.getUsername());
		return threadsVO;
	}
	
	public List<ThreadsVO> getByChannelID(Integer channelID){//xxxxxxxxxxxxxxxx
		List<ThreadsVO> threadsVOs = (List<ThreadsVO>) threadsDAO.getByChannel(channelID);		
		return threadsVOs;
	}

	@SuppressWarnings("unchecked")
	public List<ThreadsVO> getByUID(Integer uID){
		List<ThreadsVO> threadsVOs = (List<ThreadsVO>) threadsDAO.getByUID(uID);
		return threadsVOs;
	}
	
	@Transactional(propagation=Propagation.REQUIRED)
	public Boolean update(ThreadsVO threadsVO) {
		ThreadsVO oldThreadsVO = threadsDAO.getByID(ThreadsVO.class, threadsVO.getThreadsID());
		oldThreadsVO.setUpdtTime(TimeUtils.getCurrentTime());
		Boolean flag = getBaseDAO().update(oldThreadsVO);
		return flag;
	}
	
	public Boolean remove(Integer threadsID){
		ThreadsVO threadsVO = getBaseDAO().getByID(ThreadsVO.class, threadsID);
		Boolean flag = getBaseDAO().remove(threadsVO);
		return flag;
	}
	
	public List<ThreadsVO> readHoThreads(){
		@SuppressWarnings("unchecked")
		List<ThreadsVO> threadsVOs = (List<ThreadsVO>) threadsDAO.readHotThreads();
		return threadsVOs;
	}
	
/*	@Override
	public ThreadsVO getByID(Serializable ID) {
		return threadsDAO.getByID(ID);
	}

	@Override
	public List<ThreadsVO> loadAll() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Long save(ThreadsVO entity) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Boolean update(ThreadsVO entity) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Boolean remove(ThreadsVO entity) {
		// TODO Auto-generated method stub
		return null;
	}*/
	
}
